package com.wecloud.core.data.jnlservice;

import java.util.Date;
import java.util.Map;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;

import com.wecloud.core.constant.WeContext;
import com.wecloud.core.data.jnl.JnlService;
import com.wecloud.core.exception.WeException;

public class LoginJnlService extends JnlService{
	
	private String updateSql;
	
	public String getUpdateSql() {
		return updateSql;
	}

	public void setUpdateSql(String updateSql) {
		this.updateSql = updateSql;
	}

	@Override
	public void update(Map map) throws WeException {
		//更新用户信息
		getTransactionTemplate().execute(new TransactionCallback() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				try{
					map.put("updateTime", new Date());
					update(updateSql, map);
				}catch (Exception  e) {
					getAnnotationDrivenTransactionManager().rollback(status);
					throw new  WeException(e);
				}
				return null;
			}
		});
	}
	@Override
	public void prepareJnlData(WeContext context) {
		context.setData("userStatus", "1");
		context.setData("userId", context.getUser().getUserId());
	}
}
